home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / cond.pro < prev    next >
Text File  |  1997-07-08  |  3KB  |  80 lines

  1. ;$Id: cond.pro,v 1.11 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1994-1997, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;       COND
  8. ;
  9. ; PURPOSE:
  10. ;       This function computes the condition number of an N by N array.
  11. ;
  12. ; CATEGORY:
  13. ;       Complex Linear Algebra.
  14. ;
  15. ; CALLING SEQUENCE:
  16. ;       Result = COND(A)
  17. ;
  18. ; INPUTS:
  19. ;       A:      An N by N real or complex array.
  20. ;
  21. ; KEYWORD PARAMETERS:
  22. ;       DOUBLE: If set to a non-zero value, computations are done in
  23. ;               double precision arithmetic.
  24. ;
  25. ; EXAMPLE:
  26. ;       Define a complex array (a).
  27. ;         a = [[complex(1, 0), complex(2,-2), complex(-3,1)], $
  28. ;              [complex(1,-2), complex(2, 2), complex(1, 0)], $
  29. ;              [complex(1, 1), complex(0, 1), complex(1, 5)]]
  30. ;       Compute the condition number of the complex array (a) using 
  31. ;       double-precision complex arithmetic.
  32. ;         result = cond(a, /double)
  33. ;         
  34. ; PROCEDURE:
  35. ;       This function returns the condition number of an N x N real or
  36. ;       complex array (A) by explicitly computing, norm(A)*norm(A_inverse).
  37. ;       If A is real and A_inverse is invalid (due to the singularity of A 
  38. ;       or floating-point errors in the nr_invert function), the condition 
  39. ;       number is returned as a -1. If A is complex and A_inverse is invalid
  40. ;       (due to the singularity of A), calling COND.PRO results in floating-
  41. ;       point errors.
  42. ;
  43. ; REFERENCE:
  44. ;       ADVANCED ENGINEERING MATHEMATICS (seventh edition)
  45. ;       Erwin Kreyszig
  46. ;       ISBN 0-471-55380-8
  47. ;
  48. ; MODIFICATION HISTORY:
  49. ;       Written by:  GGS, RSI, April 1992
  50. ;       Modified:    GGS, RSI, February 1994
  51. ;                    Accepts complex inputs. Added DOUBLE keyword.
  52. ;       Modified:    GGS, RSI, November 1994
  53. ;                    Added support for double-precision complex inputs.
  54. ;                    Changed NR_INVERT to INVERT.
  55. ;       Modified:    GGS, RSI, April 1996
  56. ;                    Modified keyword checking and use of double precision. 
  57. ;-
  58.  
  59. FUNCTION Cond, A, Double = Double
  60.  
  61.   ON_ERROR, 2  ;Return to caller if error occurs.
  62.  
  63.   Dimension = SIZE(A)
  64.   if Dimension[0] ne 2 then MESSAGE, $
  65.     "Input array must be two-dimensional."
  66.  
  67.   if Dimension[1] ne Dimension[2] then MESSAGE, $
  68.     "Input array must be square."
  69.  
  70.   if N_ELEMENTS(Double) eq 0 then $
  71.     Double = (Dimension[Dimension[0]+1] eq 5) or $
  72.              (Dimension[Dimension[0]+1] eq 9)
  73.  
  74.   InverseA = INVERT(A, Status, Double = Double)
  75.   if Status eq 0 then RETURN, $ ;Valid inverse.
  76.     NORM(A, Double = Double) * NORM(InverseA, Double = Double) $
  77.   else RETURN, -1 ;Inversion failed.
  78.  
  79. END
  80.